package com.zyh.homework.test4;

import com.zyh.homework.test4.domain.Student;

import java.util.ArrayList;

/**
 * @Author zyh
 * @Date 2024/7/29
 * @Description TODO
 */
public class Test4 {
    public static void main(String[] args) {
        ArrayList<Student> students = new ArrayList<>();
        students.add(new Student("zyh",20,46));
        students.add(new Student("jyh",21,65));
        students.add(new Student("mjd",22,25));
        students.add(new Student("cxk",23,56));
        students.add(new Student("dz",24,15));
        Student max = max(students);
        System.out.println("最高分学员信息：姓名："+max.getName()+"年龄："+max.getAge()+"成绩："+max.getScore());
        int sum = sum(students);
        System.out.println("总分为："+sum);
        Double aDouble = averageScore(students);
        System.out.println("平均分："+aDouble);
        int count = count(students);
        System.out.println("不及格人数有"+count+"人");
    }
    //获取最高分
    public static Student max(ArrayList<Student> students){
        Student maxStudent=students.get(0);
        for (Student student : students) {
            if (student.getScore()>maxStudent.getScore()){
                Student temp=student;
                student=maxStudent;
                maxStudent=temp;
            }
        }
        return maxStudent;
    }

    //获取总成绩
    public static int sum(ArrayList<Student> students){
        int sum=0;
        for (Student student : students) {
            sum+=student.getScore();
        }
        return sum;
    }

    //获取平均分
    public static Double averageScore(ArrayList<Student> students){
        int sum = sum(students);
        return Double.valueOf(sum/students.size());
    }

    //不及格人数
    public static int count(ArrayList<Student> students){
        int count=0;
        for (Student student : students) {
            if (student.getScore()<60) {
                System.out.println("不及格学员信息：姓名：" + student.getName() + "年龄：" + student.getAge() + "成绩：" + student.getScore());
                count++;
            }
        }
        return count;
    }
}

